package com.example.designpatterns.composite;

// 抽象组件：定义了所有具体组件的公共接口
public abstract class Component {
    protected String name;

    public Component(String name) {
        this.name = name;
    }

    // 打印组件信息
    public abstract void display(int depth);

    // 添加子组件（仅容器组件需要实现）
    public void add(Component component) {
        throw new UnsupportedOperationException("Cannot add to a leaf node");
    }

    // 移除子组件（仅容器组件需要实现）
    public void remove(Component component) {
        throw new UnsupportedOperationException("Cannot remove from a leaf node");
    }

    // 获取子组件（仅容器组件需要实现）
    public Component getChild(int index) {
        throw new UnsupportedOperationException("Cannot get child from a leaf node");
    }
}